// Bristleback plugin - Copyright (c) 2010 bristleback.googlecode.com
// ---------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
// This library is distributed in the hope that it will be useful,
// but without any warranty; without even the implied warranty of merchantability
// or fitness for a particular purpose.
// You should have received a copy of the GNU Lesser General Public License along
// with this program; if not, see <http://www.gnu.org/licenses/lgpl.html>.
// ---------------------------------------------------------------------------
package pl.bristleback.server.bristle.utils;

import org.apache.log4j.Logger;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * This class is a part of Stripes Framework, version 1.5, <a href="http://www.stripesframework.org">www.stripesframework.org</a>.
 * Class is modified by Wojciech Niemiec.
 * Provides utility methods for manipulating and parsing Strings.
 *
 * @author Tim Fennell
 * @since Stripes 1.4.2
 */
public final class StringUtil {
  private static Logger log = Logger.getLogger(StringUtil.class.getName());

  public static final char DOT = '.';
  public static final char COMMA = ',';
  public static final char LEFT_BRACKET = '[';
  public static final char RIGHT_BRACKET = ']';

  private StringUtil() {
    throw new UnsupportedOperationException();
  }

  /**
   * URL-decodes {@code value} using the UTF-8 charset. Using this method eliminates the need for
   * a try/catch since UTF-8 is guaranteed to exist.
   *
   * @see java.net.URLDecoder#decode(String, String)
   */
  public static String urlDecode(String value) {
    try {
      return URLDecoder.decode(value, "UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException("Unsupported encoding?  UTF-8?  That's unpossible.");
    }
  }
}

